<?php

Yii::import('common.models.db.AnswersModel');

class FrontendAnswersModel extends AnswersModel
{
	public static function model($className=__CLASS__) {
		return parent::model($className);
	}
	public function getTotalAnswerByAsk($askId)
	{
		$sql = "SELECT count(*) as total FROM tbl_answers WHERE ask_id=:id AND published=1";
		$command = Yii::app()->db->createCommand($sql);
		$command->bindParam(':id', $askId, PDO::PARAM_INT);
		$result = $command->queryRow();
		return $result['total'];
	}
	public function getAnswerByAsk($askId, $limit, $offset)
	{
		$sql = "SELECT * FROM tbl_answers WHERE ask_id=:id AND published=1 ORDER BY id desc LIMIT :offset, :limit ";
		$command = Yii::app()->db->createCommand($sql);
		$command->bindParam(':id', $askId, PDO::PARAM_INT);
		$command->bindParam(':offset', $offset, PDO::PARAM_INT);
		$command->bindParam(':limit', $limit, PDO::PARAM_INT);
		return $command->queryAll();
	}
}